package cn.zhxu.research;

import cn.zhxu.toys.util.StringUtils;
import lombok.Getter;
import lombok.Setter;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class Result {

    private int idx;
    private int score;
    private float cosine;
    private float distance;
    private int cScore; // 模型计算出的额相似度等级
    private int dScore; // 模型计算出的额相似度等级

    public Result(int score, float cosine, float distance) {
        this.score = score;
        this.cosine = cosine;
        this.distance = distance;
    }

    public static List<Result> readDataItems(String path) throws IOException {
        try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
            List<Result> items = new ArrayList<>();
            String line = reader.readLine();
            while (StringUtils.notBlank(line)) {
                String[] split = line.split("##");
                if (split.length == 3) {
                    items.add(new Result(
                        Integer.parseInt(split[0]),
                        Float.parseFloat(split[1]),
                        Float.parseFloat(split[2])
                    ));
                }
                line = reader.readLine();
            }
            return items;
        }
    }

    @Override
    public String toString() {
        return "{idx=" + idx +
                ", score=" + score +
                ", cosine=" + cosine +
                ", distance=" + distance +
                ", cScore=" + cScore +
                ", dScore=" + dScore +
                '}';
    }
}
